import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';

import '../admob/admob_page.dart';
import 'Controller/LoginController.dart';
import 'GetViewAndGetWidget.dart';

class Home extends StatelessWidget {
  const Home({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final Controller c = Get.put(Controller());

    List<int> num=[1,2,4,6,7,78,79,79,79,77,77,79,79,7,97,46,47,76,34];
    return Scaffold(
        appBar: AppBar(title: Obx(() => Text("Clicks: ${c.count}"))),
        body: Container(
          child: Column(children: [
            Expanded(
                flex: 20,
                child: Obx(
                  () => c.data.isNotEmpty
                      ? ListView.separated(
                          itemCount: c.data.length,
                          separatorBuilder: (contenxt, index) =>
                              const Divider(),
                          itemBuilder: (BuildContext context, int index) {
                            final item = c.data[index];
                            return TextButton(
                              onPressed: () {
                                // Get.to(item.child);
                                Get.defaultDialog(
                                  radius: 10,
                                  contentPadding: EdgeInsets.zero,
                                  titlePadding: EdgeInsets.all(10),
                                  // titlePadding:
                                  //     const EdgeInsets.only(top: 16),
                                  // contentPadding: EdgeInsets.only(top: 10),
                                  title: "tips".tr,
                                  middleText: '是否退出游戏是否退出游戏是否退出游戏！',
                                  custom: Container(
                                    height: 10,
                                    width: 10,
                                    color: Colors.blue,
                                  ),
                                  actions: [
                                    Column(
                                      children: [
                                        const Divider(
                                          height: 1,
                                        ),
                                        SizedBox(
                                          height: 40,
                                          child: Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceEvenly,
                                            crossAxisAlignment:
                                                CrossAxisAlignment.center,
                                            children: [
                                              Text(
                                                "yes".tr,
                                                style: const TextStyle(
                                                    color: Colors.black),
                                              ),
                                              const VerticalDivider(),
                                              Text(
                                                "cancel".tr,
                                                style: const TextStyle(
                                                    color: Colors.black,
                                                    backgroundColor:
                                                        Colors.blue),
                                              ),
                                            ],
                                          ),
                                        ),
                                      ],
                                    )
                                  ],
                                );
                              },
                              child: Row(
                                children: [
                                  Text(item.toString() +
                                      GetPlatform.isAndroid.toString()),
                                  const Spacer(),
                                  // const Icon(
                                  //   Icons.arrow_back,
                                  //   color: Colors.blue,
                                  //   size: 20,
                                  // ),
                                  Transform(
                                    alignment: Alignment.center,
                                    transform: Matrix4.rotationZ(3.15),
                                    child: const Icon(
                                      Icons.arrow_back_ios_sharp,
                                      color: Colors.blue,
                                      size: 20,
                                    ),
                                  ),
                                ],
                              ),
                            );
                          },
                        )
                      : const Icon(
                          Icons.android,
                          color: Colors.blue,
                          size: 80,
                        ),
                )),
            GetViewAndGetWidgetExample(),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                MaterialButton(
                  onPressed: () {
                    // Get.to(const GoogleLogin());
                    c.delete();
                  },
                  color: Colors.blue,
                  height: 45,
                  shape: RoundedRectangleBorder(
                    side: const BorderSide(color: Colors.black),
                    borderRadius: BorderRadius.circular(4),
                  ),
                  child: const Text(
                    'delete',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
                MaterialButton(
                  onPressed: () {
                    // Get.to(const GoogleLogin());
                    c.test();
                  },
                  color: Colors.blue,
                  height: 45,
                  shape: RoundedRectangleBorder(
                    side: const BorderSide(color: Colors.black),
                    borderRadius: BorderRadius.circular(4),
                  ),
                  child: const Text(
                    'test',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
                MaterialButton(
                  onPressed: () {
                    // Get.to(const GoogleLogin());
                    c.update_();
                  },
                  color: Colors.blue,
                  height: 45,
                  shape: RoundedRectangleBorder(
                    side: const BorderSide(color: Colors.black),
                    borderRadius: BorderRadius.circular(4),
                  ),
                  child: const Text(
                    'update',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
                MaterialButton(
                  onPressed: () {
                    // Get.to(const GoogleLogin());
                    c.deleteAll();
                    findValuesWithinFive(num);
                  },
                  color: Colors.blue,
                  height: 45,
                  shape: RoundedRectangleBorder(
                    side: const BorderSide(color: Colors.black),
                    borderRadius: BorderRadius.circular(4),
                  ),
                  child: const Text(
                    'deleteAll',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
              ],
            ),
            Spacer(
              flex: 2,
            ),
          ]),
        ),
        floatingActionButton: FloatingActionButton(
            onPressed: () {
              c.add();
              c.increment();
            },
            child: const Icon(Icons.add)));
  }

  List<int> findValuesWithinFive(List<int> arr) {
    List<int> resultList = <int>[];

    for (int i = 0; i < arr.length; i++) {
      if (arr[i] >= -3 && arr[i] <= 3) {
        resultList.add(arr[i]);
      }
    }
     print(resultList);
    return resultList;
  }
}
